import mongoose from '../config/dbHelper';
import moment from 'moment';

const Schema = mongoose.Schema;
const LinkSchema = Schema({
  title: { type: String, required: true },
  link: { type: String, required: true },
  type: { type: String, required: true },
  created: { type: Date },
  isTop: { type: String, default: '0' },
  sort: { type: String, default: '0' }
});

LinkSchema.pre('save', function (next) {
  this.created = moment().format('YYYY-MM-DD HH:mm:ss');
  next();
});

const Link = mongoose.model('links', LinkSchema);

export default Link;
